/*
 * socket.h
 *
 *  Created on: 14/11/2012
 *      Author: leonardo
 */

#ifndef SOCKET_H_
#define SOCKET_H_
#include <iostream>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include <unistd.h>


using namespace std;

typedef struct sockaddr_in sockaddress;

class Socket {

private:
	string serverIP;
	int port;
	int caller_socket;
	sockaddress listen_address;

public:
	Socket();
	Socket(const char *, const int);
	Socket(const string &, const int);
	Socket(const Socket &);
	Socket & operator = (const Socket &);
	~Socket();

	bool createSocket(void);
	bool createSocket(const string &, const int);
	bool createSocket(const char *ip, const int port);

	bool connectToHost();
	void closeSocket();
	int  sendMessage(const void*, size_t, int);
	int  receiveMessage(void *, size_t , int);
};

#endif /* SOCKET_H_ */
